<?php

// 微信支付续费
// POST wx.pay
// Array
// (
//     [return_code] => SUCCESS
//     [return_msg] => OK
//     [appid] => wxf0956a9b28e774d7
//     [mch_id] => 1486848192
//     [nonce_str] => MqnPCmFp5AXjhcsO
//     [sign] => FF99DB27F047DB2B3AEAEC08A986EC84
//     [result_code] => SUCCESS
//     [prepay_id] => wx2018010421081439917dc01b0649933860
//     [trade_type] => MWEB
//     [mweb_url] => https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx2018010421081439917dc01b0649933860&package=1624455402
// )

namespace app\api\resource\wx;
use think\facade\Config;
use think\facade\Session;
use app\common\lib\Order as OrderCommonLib;

class Pay
{
    // 方法
    public $_method = ['POST'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '微信支付续费';
    // 参数
    public $_param  = [
        'key' => '套餐',
    ];

    public function run(&$request)
    {
        $key = $request->param('key/s','','trim');
        if ( empty($key) ) return [422,'套餐必须'];

        $item = Config::get('sg.pay.item');
        if ( !isset($item[$key]) ) return [422,'套餐不合法'];
        
        $mobile = Session::get('member.mobile');
        $title  = '续费';
        // $money  = 0.01;
        $money  = $item[$key];
        $res    = OrderCommonLib::run($title,$key,$money,$mobile);

        $arr    = [
            'out_trade_no' => $res['out_trade_no'],
            'mweb_url'     => $res['data']['mweb_url'],
        ];
        return [201,$arr];
    }
}